﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonLib
{
    public class CodeHelper
    {
        int randomCount = 0;
        /// <summary>
        /// /
        /// </summary>
        /// <returns></returns>
        public static string GetCode()
        {
            int randomCount = 0;
            randomCount++;
            string result = "";

            Guid guid = Guid.NewGuid();

            int key1 = guid.GetHashCode();
            // 摘要:获取表示此实例的日期和时间的计时周期数。
            // 返回结果: 表示此实例的日期和时间的计时周期数。该值介于 DateTime.MinValue.Ticks 和 DateTime.MaxValue.Ticks
            //     之间。
            int key2 = unchecked((int)DateTime.Now.Ticks);

            int seed = unchecked(key1 * key2 * randomCount);

            string strRandom = new Random(seed).Next(10000, 99999).ToString();
            string strRandomTwo = new Random(key2).Next(100, 999).ToString();
            string strCode = DateTime.Now.ToString("yyyy") + strRandom + strRandomTwo;
            result = strCode;
            return result;
        }


        public static string GetCode(int typeid)
        {

            string result = "";
            string strCode = "";
            switch (typeid)
            {
                case 1:
                    strCode = "S";
                    break;
                case 2:
                    strCode = "M";
                    break;
                case 3:
                    strCode = "Z";
                    break;
                case 4:
                    strCode = "D";
                    break;
                default:
                    strCode = "T";
                    break;
            }


            strCode += GetCode();
            result = strCode;
            return result;
        }
    }
}
